const backgroundAudioManager = wx.getBackgroundAudioManager()
const innerAudioContext = wx.createInnerAudioContext()
const mtjwxsdk = require("./utils/mtj-wx-sdk.js");
App({
  onLaunch: function () {
    var _this=this; 
    wx.getStorage({
      key: 'openid',
      success (res) {
        _this.globalData.openid=res.data;},
      fail(res){
        _this.getLogin();} })
      wx.getSystemInfo({
        success: (res) => {
          console.log(res.screenHeight)
          _this.screenHeight=res.screenHeight*(750/res.screenWidth);
           
        }});
  },
  getLogin: function () {
    var _this=this;
    wx.login({
      success (res) {
        console.log(res)
        if (res.code) {
          _this.globalData.loginCode=res.code;
          wx.request({
            url: 'https://mei94.com/art/web/?c=login',
            data: {cd: res.code},
            header: {'content-type': 'application/json' },
            success (res) {
              _this.globalData.openid=res.data.o;
              wx.setStorage({ key:"openid",data: res.data.o });
            }
          });
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }})
      
  },
  playBGM() {
    console.log(this.domainName)
      innerAudioContext.autoplay = true
      innerAudioContext.src = 'https://mei94.com/art/img/b.mp3';
      innerAudioContext.play();
      innerAudioContext.onEnded(() => {
          console.log('重新开始播放')
          innerAudioContext.seek(0);
          innerAudioContext.play();
      })
  },
  onShow(){
      this.playBGM();
  },
  pauseBGM() {
      innerAudioContext.pause();
  },
  replayBGM() {
    innerAudioContext.play();
  },
  //domainName:'http://192.168.3.4/art/',  
  domainName:'https://mei94.com/art/', 
  misP:true,
  screenHeight:0,
  globalData: {
    openid: ''
  }
})